﻿<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * 我的消息
* */
class Notice {
    private static $data = array();
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Notice_model','notice_model');
    }
    
    /**
     *@title 我的消息
     *@desc 我的消息(用于个人中心页)
     *
     *@input {"name":"page","type":"string","desc":"页数"}
     *@input {"name":"size","type":"string","desc":"每页显示条数"}
     *     
     *@output {"name":"code","type":"int","desc":"200:获取成功,400获取失败,无数据"}
     *@output {"name":"msg","type":"string","desc":"获取成功/获取失败"}
     *
     *@output {"name":"data","type":"array","desc":"课程数组,下面是详细说明,index代表该数组下标"}
     *@output {"name":"data[index].noticeId","desc":"消息ID","child":"1"}
     *@output {"name":"data[index].noticeContent","desc":"消息内容","child":"1"}
     *@output {"name":"data[index].readStatus","desc":"阅读状态,0未读,1已读","child":"1"}
     * */
    public function myNotice()
    {   
        $userId=$this->input->post('userId');       //登录用户ID
        if (!$userId){
            show3();
        }
        $page=$this->input->post('page');
        $size=$this->input->post('size');
        $page=empty($page)?0:$page;
        $size=empty($size)?20:$size;
        $offset=$page*$size;
        $where=['userId'=>$userId,'noticeType'=>1];
        $noticeList = $this->notice_model->getList($where, $size, $offset);
        if($noticeList){
            show200($noticeList);
        }else{
            show400();
        }
    }
    /**
     *@title 将消息标记为已读
     *@desc 将消息标记为已读
     *@input {"name":"noticeId","require":"true","type":"string","desc":"消息ID"}
     *
     *@output {"name":"code","type":"int","desc":"200:成功,400失败,3:未登录,300各种提示信息"}
     *@output {"name":"msg","type":"string","desc":"返回信息;标记成功/失败"}
     * */
    public function read()
    {
        $noticeId=$this->input->post('noticeId');
        if(!$noticeId){
            show300('消息ID不正确');
        }
        $noticeData = array('readStatus'=>1,'readTime'=>time());
        $bool = $this->notice_model->updateData($noticeData,$noticeId);
        if($bool) show200([],'已标记为已读');
        else show400('标记已读失败');
    }
    
    
    
    
    
    
    
    
    
}